package com.caosy.grassthinkremote.entity;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "user")
public class User {
    @TableId(value = "id",type = IdType.AUTO)
    private Long id;

    @Column(name = "username")
    private String username;

    @Column(name = "password")
    private String password;

    /**
     * 角色：1：管理员；2：普通用户
     */
    @Column(name = "role")
    private Integer role;

    @TableField("create_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    @TableField("update_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;

    @TableField("create_by")
    private Long createBy;

    @TableField("update_by")
    private Long updateBy;

    @TableField("last_login_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date lastLoginTime;

    public enum  RoleEnum {
        ADMIN(1,"管理员"),
        NORMAL_USER(2,"普通用户");

        public Integer roleType;

        public String roleDesc;

        RoleEnum(Integer roleType,String roleDesc) {
            this.roleType = roleType;
            this.roleDesc = roleDesc;
        }

        public static Map<Integer,String> typeToDesc = new HashMap<>(8);

        static {
            for (RoleEnum roleEnum : RoleEnum.values()) {
                typeToDesc.put(roleEnum.roleType,roleEnum.roleDesc);
            }
        }


    }
}
